home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mathfl / mf_main.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-12-05  |  16.4 KB  |  582 lines

  1. VERSION 2.00
  2. Begin Form Main 
  3.    Caption         =   "MathFlash"
  4.    ClientHeight    =   5205
  5.    ClientLeft      =   450
  6.    ClientTop       =   1680
  7.    ClientWidth     =   8490
  8.    Height          =   5895
  9.    Icon            =   MF_MAIN.FRX:0000
  10.    Left            =   390
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5205
  14.    ScaleWidth      =   8490
  15.    Top             =   1050
  16.    Width           =   8610
  17.    Begin TextBox rnd1_objects 
  18.       BackColor       =   &H00FF0000&
  19.       Height          =   285
  20.       Index           =   0
  21.       Left            =   5760
  22.       TabIndex        =   18
  23.       Text            =   " "
  24.       Top             =   1800
  25.       Width           =   255
  26.    End
  27.    Begin TextBox Text3 
  28.       FontBold        =   -1  'True
  29.       FontItalic      =   0   'False
  30.       FontName        =   "MS Sans Serif"
  31.       FontSize        =   24
  32.       FontStrikethru  =   0   'False
  33.       FontUnderline   =   0   'False
  34.       Height          =   735
  35.       Left            =   3720
  36.       TabIndex        =   1
  37.       Text            =   "Text3"
  38.       Top             =   960
  39.       Width           =   1215
  40.    End
  41.    Begin TextBox Text2 
  42.       FontBold        =   -1  'True
  43.       FontItalic      =   0   'False
  44.       FontName        =   "MS Sans Serif"
  45.       FontSize        =   24
  46.       FontStrikethru  =   0   'False
  47.       FontUnderline   =   0   'False
  48.       Height          =   735
  49.       Left            =   1080
  50.       TabIndex        =   0
  51.       Text            =   "Text2"
  52.       Top             =   960
  53.       Width           =   1215
  54.    End
  55.    Begin PictureBox Picture1 
  56.       Height          =   495
  57.       Left            =   7560
  58.       Picture         =   MF_MAIN.FRX:0302
  59.       ScaleHeight     =   465
  60.       ScaleWidth      =   465
  61.       TabIndex        =   17
  62.       Top             =   240
  63.       Width           =   495
  64.    End
  65.    Begin TextBox reward 
  66.       BackColor       =   &H00C000C0&
  67.       ForeColor       =   &H00FF0000&
  68.       Height          =   405
  69.       Index           =   0
  70.       Left            =   7560
  71.       TabIndex        =   16
  72.       Text            =   " "
  73.       Top             =   2880
  74.       Width           =   495
  75.    End
  76.    Begin TextBox rnd3_objects 
  77.       BackColor       =   &H0000C000&
  78.       ForeColor       =   &H0000C000&
  79.       Height          =   285
  80.       Index           =   0
  81.       Left            =   3600
  82.       TabIndex        =   14
  83.       Text            =   " "
  84.       Top             =   1800
  85.       Width           =   255
  86.    End
  87.    Begin TextBox rnd2_objects 
  88.       BackColor       =   &H000000C0&
  89.       ForeColor       =   &H000000FF&
  90.       Height          =   285
  91.       Index           =   0
  92.       Left            =   960
  93.       TabIndex        =   13
  94.       Text            =   " "
  95.       Top             =   1800
  96.       Width           =   255
  97.    End
  98.    Begin CommandButton quit 
  99.       Caption         =   "QUIT"
  100.       Height          =   735
  101.       Left            =   6000
  102.       TabIndex        =   7
  103.       Top             =   3720
  104.       Width           =   1335
  105.    End
  106.    Begin CommandButton Help 
  107.       Caption         =   "HELP"
  108.       Height          =   735
  109.       Left            =   4560
  110.       TabIndex        =   5
  111.       Top             =   3720
  112.       Width           =   1335
  113.    End
  114.    Begin CommandButton operation 
  115.       Caption         =   "/"
  116.       FontBold        =   -1  'True
  117.       FontItalic      =   0   'False
  118.       FontName        =   "MS Sans Serif"
  119.       FontSize        =   24
  120.       FontStrikethru  =   0   'False
  121.       FontUnderline   =   0   'False
  122.       Height          =   735
  123.       Index           =   3
  124.       Left            =   3120
  125.       TabIndex        =   11
  126.       Top             =   3720
  127.       Width           =   855
  128.    End
  129.    Begin CommandButton operation 
  130.       Caption         =   "X"
  131.       FontBold        =   -1  'True
  132.       FontItalic      =   0   'False
  133.       FontName        =   "MS Sans Serif"
  134.       FontSize        =   24
  135.       FontStrikethru  =   0   'False
  136.       FontUnderline   =   0   'False
  137.       Height          =   735
  138.       Index           =   2
  139.       Left            =   2160
  140.       TabIndex        =   10
  141.       Top             =   3720
  142.       Width           =   855
  143.    End
  144.    Begin CommandButton operation 
  145.       Caption         =   "-"
  146.       FontBold        =   -1  'True
  147.       FontItalic      =   0   'False
  148.       FontName        =   "MS Sans Serif"
  149.       FontSize        =   24
  150.       FontStrikethru  =   0   'False
  151.       FontUnderline   =   0   'False
  152.       Height          =   735
  153.       Index           =   1
  154.       Left            =   1200
  155.       TabIndex        =   9
  156.       Top             =   3720
  157.       Width           =   855
  158.    End
  159.    Begin CommandButton operation 
  160.       Caption         =   "+"
  161.       FontBold        =   -1  'True
  162.       FontItalic      =   0   'False
  163.       FontName        =   "MS Sans Serif"
  164.       FontSize        =   24
  165.       FontStrikethru  =   0   'False
  166.       FontUnderline   =   0   'False
  167.       Height          =   735
  168.       Index           =   0
  169.       Left            =   240
  170.       TabIndex        =   8
  171.       Top             =   3720
  172.       Width           =   855
  173.    End
  174.    Begin TextBox Text1 
  175.       FontBold        =   -1  'True
  176.       FontItalic      =   0   'False
  177.       FontName        =   "MS Sans Serif"
  178.       FontSize        =   24
  179.       FontStrikethru  =   0   'False
  180.       FontUnderline   =   0   'False
  181.       Height          =   735
  182.       Left            =   5880
  183.       TabIndex        =   3
  184.       Tag             =   "text1"
  185.       Text            =   "Text1"
  186.       Top             =   960
  187.       Width           =   1215
  188.    End
  189.    Begin CommandButton hidden 
  190.       Caption         =   "ACCEPT"
  191.       Default         =   -1  'True
  192.       Height          =   375
  193.       Left            =   5880
  194.       TabIndex        =   6
  195.       Top             =   480
  196.       Width           =   1215
  197.    End
  198.    Begin Label Label1 
  199.       Caption         =   "Bonus Bell"
  200.       Height          =   255
  201.       Left            =   7320
  202.       TabIndex        =   19
  203.       Top             =   0
  204.       Width           =   975
  205.    End
  206.    Begin Label score 
  207.       BackColor       =   &H0000FFFF&
  208.       Caption         =   " "
  209.       Height          =   255
  210.       Left            =   2760
  211.       TabIndex        =   15
  212.       Top             =   4800
  213.       Width           =   2175
  214.    End
  215.    Begin Label correct 
  216.       BackColor       =   &H00FFFF00&
  217.       Caption         =   " "
  218.       Height          =   255
  219.       Left            =   360
  220.       TabIndex        =   12
  221.       Top             =   4800
  222.       Width           =   2055
  223.    End
  224.    Begin Label Label3 
  225.       Caption         =   "="
  226.       FontBold        =   -1  'True
  227.       FontItalic      =   0   'False
  228.       FontName        =   "MS Sans Serif"
  229.       FontSize        =   24
  230.       FontStrikethru  =   0   'False
  231.       FontUnderline   =   0   'False
  232.       Height          =   495
  233.       Left            =   5280
  234.       TabIndex        =   2
  235.       Top             =   1080
  236.       Width           =   375
  237.    End
  238.    Begin Label operand 
  239.       Caption         =   "+"
  240.       FontBold        =   -1  'True
  241.       FontItalic      =   0   'False
  242.       FontName        =   "MS Sans Serif"
  243.       FontSize        =   24
  244.       FontStrikethru  =   0   'False
  245.       FontUnderline   =   0   'False
  246.       Height          =   495
  247.       Left            =   2880
  248.       TabIndex        =   4
  249.       Top             =   1080
  250.       Width           =   375
  251.    End
  252.    Begin Menu utilityname 
  253.       Caption         =   "Utilities"
  254.       Begin Menu limits 
  255.          Caption         =   "&Change Limits"
  256.       End
  257.    End
  258.    Begin Menu About 
  259.       Caption         =   "About"
  260.    End
  261. Rem sound drivers
  262. Declare Function closesound Lib "sound.drv" () As Integer
  263. Declare Function opensound Lib "sound.drv" () As Integer
  264. Declare Function SetVoiceSound Lib "sound.drv" (ByVal nSource%, ByVal Freq&, ByVal nDuration%) As Integer
  265. Declare Function StartSound Lib "sound.drv" () As Integer
  266. Sub About_Click ()
  267. about_form.Show
  268. End Sub
  269. Sub Command1_Click ()
  270. set_text_focus
  271. End Sub
  272. Sub display_objects ()
  273. Rem loading control array
  274. Dim starting, offset As Integer
  275. Rem drawing blocks for text1 (product box)
  276.     rnd1_objects(0).Visible = True
  277.     starting = 5760
  278.     offset = 300
  279.     For i = 1 To (answer - 1)
  280.         Load rnd1_objects(i)
  281.         rnd1_objects(i).Left = starting + offset
  282.         If i > 14 Then
  283.             rnd1_objects(i).Top = 3000
  284.         ElseIf i > 9 Then
  285.             rnd1_objects(i).Top = 2600
  286.         ElseIf i > 4 Then
  287.             rnd1_objects(i).Top = 2200
  288.         Else
  289.             rnd1_objects(i).Top = 1800
  290.         End If
  291.         rnd1_objects(i).Visible = -1
  292.         rnd1_objects(i).Text = ""
  293.         If offset = 1200 Then
  294.             offset = 0
  295.         Else
  296.             offset = offset + 300
  297.         End If
  298.     Next i
  299.     rnd2_objects(0).Visible = True
  300.     starting = 960
  301.     offset = 300
  302.     For i = 1 To (rnd1 - 1)
  303.         Load rnd2_objects(i)
  304.         rnd2_objects(i).Left = starting + offset
  305.         If i > 4 Then
  306.             rnd2_objects(i).Top = 2200
  307.         Else
  308.             rnd2_objects(i).Top = 1800
  309.         End If
  310.         rnd2_objects(i).Visible = -1
  311.         rnd2_objects(i).Text = ""
  312.         If offset = 1200 Then
  313.             offset = 0
  314.         Else
  315.             offset = offset + 300
  316.         End If
  317.     Next i
  318.     rnd3_objects(0).Visible = True
  319.     starting = 3600
  320.     offset = 300
  321.     For i = 1 To (rnd2 - 1)
  322.         Load rnd3_objects(i)
  323.         rnd3_objects(i).Left = starting + offset
  324.         If i > 4 Then
  325.             rnd3_objects(i).Top = 2200
  326.         Else
  327.             rnd3_objects(i).Top = 1800
  328.         End If
  329.         rnd3_objects(i).Visible = -1
  330.         rnd3_objects(i).Text = ""
  331.         If offset = 1200 Then
  332.             offset = 0
  333.         Else
  334.             offset = offset + 300
  335.         End If
  336.     Next i
  337. End Sub
  338. Sub find_last ()
  339. lastrecord = LOF(1) / Len(student_rec)
  340. End Sub
  341. Sub form_load ()
  342.     Unload limit
  343.     main.Show
  344.     load_operation
  345. Rem picture1.Picture = LoadPicture("misc07.ico")
  346.     i = opensound()
  347. End Sub
  348. Sub Help_Click ()
  349. nl$ = Chr$(13) + Chr$(10)
  350. msg$ = "Type the answer to complete the equation in the " + nl$
  351. msg$ = msg$ + "empty box.  Press ENTER or click 'ACCEPT'. " + nl$
  352. msg$ = msg$ + nl$
  353. msg$ = msg$ + "Boxes will be drawn when upper limit = 10 and" + nl$
  354. msg$ = msg$ + "the operation is addition or subtraction."
  355. msg$ = msg$ + nl$
  356. msg$ = msg$ + "Five correct answers rings bell and adds 1,000 points."
  357. MsgBox msg$
  358. set_text_focus
  359. End Sub
  360. Sub hidden_Click ()
  361.     Select Case rnd_box
  362.     Case 1
  363.         user_input = Val(text1.Text)
  364.     Case 2
  365.         user_input = Val(text2.Text)
  366.     Case 3
  367.         user_input = Val(text3.Text)
  368.     End Select
  369.     If user_input = correct_answer Then
  370.         Call sound(1000, 100)
  371. Rem        msg$ = "Right Answer!"
  372.         answer_flag = 0
  373.         iteration = iteration + 1
  374.         num_right = num_right + 1
  375.         highscore = highscore + 100
  376.         reward_draw
  377.         percent_correct = Int((num_right / iteration) * 100)
  378.         correct.Caption = Str$(percent_correct) + " % correct"
  379.         score.Caption = "Score : " + Str$(highscore)
  380.         If objects = True Then
  381.             remove_objects
  382.         End If
  383.     Else
  384.         Call sound(500, 100)
  385.         msg$ = "Try Again."
  386.         MsgBox msg$
  387.         iteration = iteration + 1
  388.         percent_correct = Int((num_right / iteration) * 100)
  389.         correct.Caption = Str$(percent_correct) + " % correct"
  390.         answer_flag = -1
  391.         Select Case rnd_box
  392.         Case 1
  393.             text1.Text = " "
  394.         Case 2
  395.             text2.Text = " "
  396.         Case 3
  397.             text3.Text = " "
  398.         End Select
  399.     End If
  400. form_load
  401. End Sub
  402. Sub hide_objects ()
  403. rnd1_objects(0).Visible = False
  404. rnd2_objects(0).Visible = False
  405. rnd3_objects(0).Visible = False
  406. End Sub
  407. Sub limits_Click ()
  408.     limit.Show
  409. End Sub
  410. Sub load_operation ()
  411. Rem answer_flag = 0 then right answer, -1 then wrong answer
  412. If answer_flag = 0 Then
  413.         Randomize
  414.         rnd_box = Int(Rnd * 3) + 1
  415.         Select Case case_index
  416.         Case 0
  417.             rnd1 = Int(Rnd * (upper_limit + 1))
  418.             rnd2 = Int(Rnd * (upper_limit + 1))
  419.             answer = rnd1 + rnd2
  420.             If upper_limit = 10 Then
  421.                 objects = True
  422.                 display_objects
  423.                 test_zero
  424.             Else
  425.                 objects = False
  426.                 hide_objects
  427.             End If
  428.         Case 1
  429.             rnd1 = Int(Rnd * (upper_limit + 1))
  430.             Do
  431.                 rnd2 = Int(Rnd * (upper_limit + 1))
  432.             Loop Until rnd1 >= rnd2
  433.             answer = rnd1 - rnd2
  434.             If upper_limit = 10 Then
  435.                 objects = True
  436.                 display_objects
  437.                 test_zero
  438.             Else
  439.                 objects = False
  440.                 hide_objects
  441.             End If
  442.         Case 2
  443.             rnd1 = Int(Rnd * (upper_limit)) + 1
  444.             rnd2 = Int(Rnd * (upper_limit)) + 1
  445.             answer = rnd1 * rnd2
  446.             hide_objects
  447.             objects = False
  448.         Case 3
  449.             Rem rnd2 can't be 0
  450.             Do
  451.             rnd1 = Int(Rnd * (upper_limit)) + 1
  452.             rnd2 = Int(Rnd * (upper_limit)) + 1
  453.             Loop Until (rnd1 / rnd2 - Int(rnd1 / rnd2)) = 0
  454.             answer = rnd1 / rnd2
  455.             hide_objects
  456.             objects = False
  457.         End Select
  458. Rem        set_text_focus
  459. Rem        MsgBox Str$(rnd_box)
  460.         Select Case rnd_box
  461.         Case 1
  462.             text1.Text = " "
  463.             text2.Text = Str$(rnd1)
  464.             text3.Text = Str$(rnd2)
  465.             text1.SetFocus
  466.             correct_answer = answer
  467.         Case 2
  468.             text2.Text = " "
  469.             text1.Text = Str$(answer)
  470.             text3.Text = Str$(rnd2)
  471.             text2.SetFocus
  472.             correct_answer = rnd1
  473.         Case 3
  474.             text3.Text = " "
  475.             text1.Text = Str$(answer)
  476.             text2.Text = Str$(rnd1)
  477.             text3.SetFocus
  478.             correct_answer = rnd2
  479.         End Select
  480. End If
  481. End Sub
  482. Sub operation_Click (Index As Integer)
  483. answer_flag = 0
  484. If objects = True Then
  485.     remove_objects
  486. End If
  487. Select Case Index
  488. Case 0
  489.     operand.Caption = "+"
  490.     case_index = 0
  491. Case 1
  492.     operand.Caption = "-"
  493.     case_index = 1
  494. Case 2
  495.     operand.Caption = "x"
  496.     case_index = 2
  497. Case 3
  498.     operand.Caption = "/"
  499.     case_index = 3
  500. End Select
  501. load_operation
  502. End Sub
  503. Sub quit_Click ()
  504. If percent_correct > 0 Then
  505.     On Error Resume Next
  506.     Open "STUDENT.DAT" For Random As #1 Len = Len(student_rec)
  507.     find_last
  508.     lastrecord = lastrecord + 1
  509.     student_rec.name = student_name
  510.     student_rec.time = Str$(percent_correct)
  511.     Put #1, lastrecord, student_rec
  512.     Close #1
  513. End If
  514. i = closesound()
  515. End Sub
  516. Sub remove_objects ()
  517. hide_objects
  518. For i = 1 To (answer - 1)
  519.     Unload rnd1_objects(i)
  520. Next i
  521. For i = 1 To (rnd1 - 1)
  522.     Unload rnd2_objects(i)
  523. Next i
  524. For i = 1 To (rnd2 - 1)
  525.     Unload rnd3_objects(i)
  526. Next i
  527. End Sub
  528. Sub renew_data_file_Click ()
  529. Kill "d:\vb2\student.dat"
  530. End Sub
  531. Sub reward_draw ()
  532.     reward_counter = reward_counter + 1
  533.     If reward_counter = 5 Then
  534.         reward_hide
  535.     End If
  536.     If reward_counter > 0 Then
  537.         Load reward(reward_counter)
  538.     End If
  539.     reward_y_start = 2880
  540.     reward_y = reward_y_start - (reward_counter * 500)
  541.     reward(reward_counter).Top = reward_y
  542.     reward(reward_counter).Visible = -1
  543. End Sub
  544. Sub reward_hide ()
  545. For i = 1 To 4
  546.     Unload reward(i)
  547. Next i
  548. highscore = highscore + 1000
  549. reward_counter = 0
  550. Call sound(800, 50)
  551. Call sound(1000, 50)
  552. Call sound(1200, 50)
  553. End Sub
  554. Sub set_text_focus ()
  555.     Select Case rnd_box
  556.     Case 1
  557.         text1.SetFocus
  558.     Case 2
  559.         text2.SetFocus
  560.     Case 3
  561.         text3.SetFocus
  562.     End Select
  563. End Sub
  564. Sub sound (ByVal Frequency As Long, ByVal Duration As Integer)
  565.     Frequency = Frequency * 65536
  566.     i = SetVoiceSound(1, Frequency, Duration)
  567.     i = StartSound()
  568. End Sub
  569. Sub test_zero ()
  570. If rnd1 = 0 Then
  571.     rnd2_objects(0).Visible = False
  572. End If
  573. If rnd2 = 0 Then
  574.     rnd3_objects(0).Visible = False
  575. End If
  576. If answer = 0 Then
  577.     rnd1_objects(0).Visible = False
  578. End If
  579. End Sub
  580. Sub upperlim_Click ()
  581. End Sub
  582.